﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Shop.Model;

namespace Shop.Framework.Control {
    public class CartSubPart : CartControl {
        public OrderItem LastAdded { get {
                return GetLastItem();
        } }

        public ProductImage DefaultImage {
            get {

                if (LastAdded == null)
                    return null;

                return LastAdded.Product.ProductImages.FirstOrDefault(x => x.IsDefault);
            }
        }

        private OrderItem GetLastItem() {
            return OrderItems.LastOrDefault();
        }



        protected override void OnInit(EventArgs e) {
            try {

                //TODO: Set to key
                OrderItems = ViewData["OrderList"] as List<OrderItem>;
                base.OnInit(e);
                
            } catch (Exception ex) {
                throw ex;
            }
        }
    }
}
